unit WebBrokerContainerUnit;

interface

uses System.SysUtils, System.Classes,
  Datasnap.DSHTTPCommon, Datasnap.DSHTTP,
  Datasnap.DSServer, Datasnap.DSCommonServer, DSService,
  Datasnap.DSAuth, IndyPeerImpl, DbxCompressionFilter, WARCommons;

type
  TWebBrokerContainer = class(TDataModule)
    DSServer: TDSServer;
    DSHTTPService: TDSHTTPService;
    DSAuthenticationManager: TDSAuthenticationManager;
    DSServerClass: TDSServerClass;
    procedure DSServerClassGetClass(DSServerClass: TDSServerClass;
      var PersistentClass: TPersistentClass);
    procedure DSAuthenticationManagerUserAuthorize(Sender: TObject;
      EventObject: TDSAuthorizeEventObject; var valid: Boolean);
    procedure DSAuthenticationManagerUserAuthenticate(Sender: TObject;
      const Protocol, Context, User, Password: string; var valid: Boolean;
      UserRoles: TStrings);
    procedure DSServerConnect(DSConnectEventObject: TDSConnectEventObject);
  private
    { Private declarations }
  public
  end;

var
  WebBrokerContainer: TWebBrokerContainer;

implementation

uses Winapi.Windows, WebBrokerMethodsUnit, WebBrokerUnit;

{$R *.dfm}

procedure TWebBrokerContainer.DSServerClassGetClass(DSServerClass
  : TDSServerClass; var PersistentClass: TPersistentClass);
begin
  PersistentClass := WebBrokerMethodsUnit.TwebBrokerMethods;
end;

procedure TWebBrokerContainer.DSServerConnect(DSConnectEventObject
  : TDSConnectEventObject);
begin
  logmessage('Connection from: ' + TDSSessionManager.GetThreadSession.GetData
    ('RemoteIP'));
  frmWebBroker.txtLog.Lines.Add('Connection from: ' +
    TDSSessionManager.GetThreadSession.GetData('RemoteIP'));
end;

procedure TWebBrokerContainer.DSAuthenticationManagerUserAuthenticate
  (Sender: TObject; const Protocol, Context, User, Password: string;
  var valid: Boolean; UserRoles: TStrings);
begin
  { TODO : Validate the client user and password.
    If role-based authorization is needed, add role names to the UserRoles parameter }
  valid := True;
end;

procedure TWebBrokerContainer.DSAuthenticationManagerUserAuthorize
  (Sender: TObject; EventObject: TDSAuthorizeEventObject; var valid: Boolean);
begin
  { TODO : Authorize a user to execute a method.
    Use values from EventObject such as UserName, UserRoles, AuthorizedRoles and DeniedRoles.
    Use DSAuthenticationManager1.Roles to define Authorized and Denied roles
    for particular server methods. }
  valid := True;
end;

end.
